<%@ page import="cn.ixinjiu.libraryMangement.entity.BorrowInfo" %>
<%@ page import="cn.ixinjiu.libraryMangement.dao.impl.BorrowInfoDaoImpl" %>
<%@ page import="cn.ixinjiu.libraryMangement.dao.IBorrowInfoDao" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="cn.ixinjiu.libraryMangement.dao.IBookInfoDao" %>
<%@ page import="cn.ixinjiu.libraryMangement.dao.impl.BookInfoDaoImpl" %>
<%@ page import="cn.ixinjiu.libraryMangement.entity.BookInfo" %>
<%@ page import="cn.ixinjiu.libraryMangement.service.IBookInfoService" %>
<%@ page import="cn.ixinjiu.libraryMangement.service.impl.BookInfoServiceImpl" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/5/20
  Time: 11:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>更改图书信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <script src="/static/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<%
    IBookInfoService bookInfoService = new BookInfoServiceImpl();
    BookInfo bookInfoById = bookInfoService.getBookInfoById(Integer.parseInt(request.getParameter("id")));

    // url
    StringBuffer requestURL = request.getRequestURL();
    String[] split = requestURL.toString().split("jsp");
    String baseURL = split[0]; // http://localhost:8081/
%>


<form class="layui-form   layui-form-pane" action="">
    <%-- 隐藏id --%>
    <input type="id" name="id" value=<%=bookInfoById.getId() %> class="layui-hide">
    <!-- 图书名称 -->
    <div class="layui-form-item">
        <label class="layui-form-label">图书名称</label>
        <div class="layui-input-block">
            <input type="text" name="book_name" value=<%=bookInfoById.getBookName() %> required lay-verify="required"
                   placeholder="请输入图书名称" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>
        <%-- 图书图片 --%>
        <div class="layui-form-item">
            <label class="layui-form-label">图书图片</label>
            <div style="width: 150px; height: 200px; border: 1px black solid; float: left">
                <img src=<%=baseURL%><%=bookInfoById.getBookPic()%> disabled style="width: 150px; height: 200px" id="avatar">
            </div>
        </div>
    <!-- 书籍分类 -->
    <div class="layui-form-item">
        <label class="layui-form-label">书籍分类</label>
        <div class="layui-input-block">
            <input type="text" name="sort_id" value=<%=bookInfoById.getSortId() %> required lay-verify="required"
                   placeholder="请输入书籍分类" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>
    <!-- 作者 -->
    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-block">
            <input type="text" name="author" value=<%=bookInfoById.getAuthor() %> required lay-verify="required"
                   placeholder="请输入作者" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>
        <!-- 出版社 -->
        <div class="layui-form-item">
            <label class="layui-form-label">出版社</label>
            <div class="layui-input-block">
                <input type="text" name="publisher" value=<%=bookInfoById.getPublisher() %> required lay-verify="required"
                       placeholder="请输入出版社" autocomplete="off" class="layui-input" disabled>
            </div>
        </div>
    <!-- 出版日期 -->
    <div class="layui-form-item">
        <label class="layui-form-label">出版日期</label>
        <div class="layui-input-block">
            <% if (bookInfoById.getPublisherAt() == null) { %>
            <input type="text" name="publisher_at" value="" required lay-verify="required"
                   placeholder="请输入出版日期" autocomplete="off" class="layui-input" id="publisher_at" disabled>
            <% } else {%>
            <input type="text" name="publisher_at" value=<%=bookInfoById.getPublisherAt() %> required
                   lay-verify="required"
                   placeholder="请输入出版日期" autocomplete="off" class="layui-input" id="publisher_at" disabled>
            <%}%>
        </div>
    </div>
    <!-- ISBN号 -->
    <div class="layui-form-item">
        <label class="layui-form-label">ISBN号</label>
        <div class="layui-input-block">
            <input type="text" name="isbn" value=<%=bookInfoById.getIsbn() %> title="已归还"
                   lay-verify="required" placeholder="请输入ISBN号" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>
    <!-- 图书状态 -->
    <div class="layui-form-item">
        <label class="layui-form-label">图书状态</label>
        <div class="layui-input-block">
            <input type="text" name="status" value=<%=bookInfoById.getStatus() %>  lay-verify="required"
                   placeholder="请输入图书状态" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">朕已知晓</button>
        </div>
    </div>

</form>

<script>

    layui.use(['form', 'laydate', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form
        var laydate = layui.laydate; // 日期选择
        var upload = layui.upload;

        // 执行实例
        upload.render({
            elem: '#bookPicUpload' // 绑定元素
            , url: '/upload' // 上传接口
            , done: function (res) {
                // 成功回调
                layer.msg('上传成功', {
                    icon: 6,
                    time: 500
                })
                // 图片回显
                $('#avatar').attr('src', res.avatar);
            }
            , error: function (){
                // 异常回调
            }
        });

        // 执行借书日期实例
        laydate.render({
            elem: '#publisher_at' //指定元素
        });
        // 监听提交
        form.on('submit(formDemo)', function (data) {
            layer.closeAll();
            return false;
        });
    });

</script>

</body>
</html>
